#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e7 + 10, INF = 0x3f3f3f3f;

int n, A, B, C;
int a[N];

void solve()
{
    scanf("%d%d%d%d%d", &n, &A, &B, &C, a + 1);
    for (int i = 2; i <= n; i++)
        a[i] = ((long long)a[i - 1] * A + B) % 100000001;
    for (int i = 1; i <= n; i++)
        a[i] = a[i] % C + 1;

    double ans = 0;
    for (int i = 1;i < n;i++) {
        ans += 1.0l / a[i] * min(a[i], a[i + 1]) / a[i + 1];
    }
    ans += 1.0l / a[n] * min(a[1], a[n]) / a[1];
    cout << fixed << setprecision(3);
    cout << ans;
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}